/**
 * Created by hc on 2016/11/29.
 */
function initUploader(borwse_btn_id) {
    var uploader = new plupload.Uploader({
        runtimes: 'html5,flash,silverlight,html4',
        browse_button: borwse_btn_id, // you can pass an id...
        url: '/process/upload',
        flash_swf_url: '../js/plupload3/Moxie.swf',
        silverlight_xap_url: '../js/plupload3/Moxie.xap',

        filters: {
            max_file_size: '10mb',
            mime_types: [
                {title: "Image files", extensions: "jpg,gif,png"},
                {title: "Zip files", extensions: "zip"},
                {title: "Pdf files", extensions: "pdf"}
            ]
        },

        init: {
            FilesAdded: function (up, files) {
                uploader.start();
            },

            UploadProgress: function (up, file) {
            },
            FileUploaded: function (uploader, file, result) {
                var path = eval("("+result.response+")");

                var type = file.type;
                $("#"+borwse_btn_id).addClass('transparent');
                if(type.indexOf('pdf') >=0){
                    $("#"+borwse_btn_id).parent().find("img").remove();
                    $("#"+borwse_btn_id).parent().append("<img class='uploaded-img' src='"+$('#server_name').val()+"/Public/Uploads/pdf.png'>");
                }else{
                    $("#"+borwse_btn_id).parent().find("img").remove();
                    $("#"+borwse_btn_id).parent().append("<img class='uploaded-img'  src='"+$('#server_name').val()+path.path+"'>");
                }
                //

                $("#"+borwse_btn_id+"_hidden").val(path.path);
            },
            Error: function (up, err) {
                alert(err.message);
            }
        }
    });

    uploader.init();
}
